package com.sfh.gd.domain.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.mybatisflex.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 *  赛事-队伍
 *
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("gd_game_team")
public class GameTeamDO implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id(keyType = KeyType.Auto)
    private Long id;
    /**
     * 队伍编号
     */
    private String code;
    /**
     * 赛事ID
     */
    private Long gameId;
    /**
     * 积分
     */
    private Long scoreValue;

    /**
     * 状态 1 正常 -1 淘汰 2禁赛 3比赛中 4等待中 5已晋级
     */
    private Integer state;
    /**
     * 轮次
     */
    private Integer roundCount;

    /**
     * 队员1-会员ID
     */
    private Long teamUser1Id;
    /**
     * 队员1-会员
     */
    @RelationOneToOne(selfField = "teamUser1Id", targetField = "id")
    private MemberDO member1;

    /**
     * 队员2-会员ID
     */
    private Long teamUser2Id;
    /**
     * 队员2-会员
     */
    @RelationOneToOne(selfField = "teamUser2Id", targetField = "id")
    private MemberDO member2;

    /**
     * 创建时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private LocalDateTime createTime;

    /**
     * 更新时间 数据变动自动更新
     */
    @Column(onUpdateValue = "LocalDateTime.now()")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private LocalDateTime updateTime;
    /**
     * 队伍PK未匹配中次数
     */
    private Long unPkCount;
    /**
     * 队伍等待PK时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private LocalDateTime   WaitingTime;

    public GameTeamDO addScoreValue(long value) {
        //加分
        this.scoreValue += value;
        return this;
    }
    public GameTeamDO subScoreValue(long value) {
        //减分
        this.scoreValue -= value;
        return this;
    }
    public GameTeamDO addRoundCount() {
        //加轮次
        this.roundCount += 1;
        return this;
    }
}
